package com.bsoft.exchange.controller.prescription;

import com.bsoft.exchange.pojo.AuditNetPrescriptionPojo;
import com.bsoft.exchange.pojo.NetPrescriptionDetailsPojo;
import com.bsoft.exchange.pojo.NetPrescriptionListPojo;
import com.bsoft.exchange.response.ResponseEntity;
import com.bsoft.exchange.service.NetPrescriptionService;
import com.bsoft.exchange.util.BaseResponse;
import com.bsoft.exchange.util.Constant;
import com.bsoft.exchange.util.TextUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * 创建日期 : 2019/10/23
 * 创建人 : 赵太行
 * 在线审方模块
 */
@RestController
public class NetPrescriptionController {
    @Autowired
    NetPrescriptionService netPrescriptionService;

    /**
     * 获取审方列表
     */
    @ApiOperation("获取审方列表")
    @RequestMapping(value = "prescription/list", method = RequestMethod.POST, produces = "application/json")
    public ResponseEntity getNetPrescriptionList(@RequestBody @Validated NetPrescriptionListPojo pojo) {
        ResponseEntity responseEntity = new ResponseEntity();
        BaseResponse baseResponse = netPrescriptionService.getNetPrescriptionListService(pojo);
        responseEntity.setCode(baseResponse.getCode());
        responseEntity.setMessage(baseResponse.getMessage());
        responseEntity.setData(baseResponse.getData());
        return responseEntity;
    }

    /**
     * 获取审方详情
     */
    @ApiOperation("获取审方详情")
    @RequestMapping(value = "prescription/detail", method = RequestMethod.POST, produces = "application/json")
    public ResponseEntity getNetPrescriptionDetail(@RequestBody @Validated NetPrescriptionDetailsPojo pojo) {
        ResponseEntity responseEntity = new ResponseEntity();
        BaseResponse baseResponse = netPrescriptionService.getNetPrescriptionDetailsService(pojo);
        responseEntity.setCode(baseResponse.getCode());
        responseEntity.setMessage(baseResponse.getMessage());
        responseEntity.setData(baseResponse.getData());
        return responseEntity;
    }

    /**
     * 提交处方审核信息
     */
    @ApiOperation("提交审核信息")
    @RequestMapping(value = "prescription/audit", method = RequestMethod.POST, produces = "application/json")
    public ResponseEntity auditNetPrescription(@RequestBody @Validated AuditNetPrescriptionPojo pojo) {
        ResponseEntity responseEntity = new ResponseEntity();
        try {
            BaseResponse baseResponse = netPrescriptionService.auditPrescriptionData(pojo);
            responseEntity.setCode(baseResponse.getCode());
            responseEntity.setMessage(baseResponse.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            responseEntity.setCode(Constant.errorTag);
            responseEntity.setMessage("插入失败");
        }

        return responseEntity;
    }

    /**
     * 提交处方审核信息
     */
    @ApiOperation("提交重新审核信息")
    @RequestMapping(value = "prescription/auditRetry", method = RequestMethod.POST, produces = "application/json")
    public ResponseEntity auditRetryNetPrescription(@RequestBody Map<String, String> mapPojo) {
        ResponseEntity responseEntity = new ResponseEntity();
        String organizationId = mapPojo.get("organizationId");
        String prescriptionId = mapPojo.get("prescriptionId");
        if (TextUtils.isEmpty(organizationId) || TextUtils.isEmpty(prescriptionId)) {
            responseEntity.setCode(Constant.errorTag);
            responseEntity.setMessage("请求参数缺失");
            return responseEntity;
        }
        BaseResponse baseResponse = netPrescriptionService.auditRetryPrescriptionData(organizationId, prescriptionId);
        responseEntity.setCode(baseResponse.getCode());
        responseEntity.setMessage(baseResponse.getMessage());
        return responseEntity;
    }

    /**
     * 获取药房列表
     */
    @ApiOperation("获取药房列表")
    @RequestMapping(value = "prescription/pharmacyList", method = RequestMethod.POST, produces = "application/json")
    public ResponseEntity getPharmacyList(@RequestBody Map<String, String> mapPojo) {
        ResponseEntity responseEntity = new ResponseEntity();
        String organizationId = mapPojo.get("organizationId");
        String doctorId = mapPojo.get("doctorId");
        if (TextUtils.isEmpty(organizationId) || TextUtils.isEmpty(doctorId)) {
            responseEntity.setCode(Constant.errorTag);
            responseEntity.setMessage("请求参数缺失");
            return responseEntity;
        }
        BaseResponse baseResponse = netPrescriptionService.getPharmacyListServuce(organizationId, doctorId);
        responseEntity.setCode(baseResponse.getCode());
        responseEntity.setMessage(baseResponse.getMessage());
        responseEntity.setData(baseResponse.getData());
        return responseEntity;
    }
}
